﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Collections;

namespace ConnectLib.DAO
{
    [Serializable]
    public class StaffDao
    {
		private string _staffcode;
		private string _fullName;
		private string _address;
        private string _phone;
        private DateTime _birthday;
        private string _password;
		private byte _ptnright;
        private byte _active;
		private int _branch;
        private string _skype;
        private string _email;
        private byte _support;
        private byte _sex;

		public string StaffCode
        {
            get { return _staffcode; }
            set { _staffcode = value; }
        }
        
        public string FullName
        {
            get { return _fullName; }
            set { _fullName = value; }
        }
		
		public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
		
		public string Phone
        {
            get { return _phone; }
            set { _phone = value; }
        }

        public DateTime Birthday
        {
            get { return _birthday; }
            set { _birthday = value; }
        }
        
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
		
		public byte PTNRight
        {
            get { return _ptnright; }
            set { _ptnright = value; }
        }

        public byte Active
        {
            get { return _active; }
            set { _active = value; }
        }
		
		public int Branch
        {
            get { return _branch; }
            set { _branch = value; }
        }

        public string Skype
        {
            get { return _skype; }
            set { _skype = value; }
        }

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public byte Support
        {
            get { return _support; }
            set { _support = value; }
        }

        public byte Sex
        {
            get { return _sex; }
            set { _sex = value; }
        }

        public void InitEmptyValue()
        {
			_staffcode = string.Empty;
            _fullName = string.Empty;
			_address = string.Empty;
			_phone = string.Empty;
            _birthday = DateTime.Now;
            _password = string.Empty;
			_ptnright = 0;
            _active = 1;
            _branch = 0;
            _skype =string.Empty;
            _email = string.Empty;
            _support = 0;
            _sex = 1;
        }

        public StaffDao()
        {
            InitEmptyValue();
        }

        public StaffDao(Hashtable hsObj)
        {
            InitEmptyValue();
            try
            {
                PropertyInfo[] arrProInfo = this.GetType().GetProperties();
                PropertyInfo proInfo;
                object objValue;
                string sValue;
                string proName;
                for (int i = 0; i < arrProInfo.Length; i++)
                {
                    proInfo = arrProInfo[i];
                    proName = proInfo.Name.ToLower();
                    if (hsObj.ContainsKey(proName))
                    {
                        objValue = hsObj[proName];
                        if (proInfo.PropertyType.Name.ToLower() == "byte[]")
                        {
                            if (objValue != null && objValue != DBNull.Value)
                            {
                                proInfo.SetValue(this, (byte[])objValue, null);
                            }
                        }
                        else
                        {
                            sValue = Convert.ToString(objValue);
                            if (string.IsNullOrEmpty(sValue))
                                continue;
                            switch (proInfo.PropertyType.Name.ToLower())
                            {
                                case "byte":
                                    proInfo.SetValue(this, Convert.ToByte(objValue), null);
                                    break;
                                case "int64":
                                    proInfo.SetValue(this, Convert.ToInt64(objValue), null);
                                    break;
                                case "int32":
                                    proInfo.SetValue(this, Convert.ToInt32(objValue), null);
                                    break;
                                case "datetime":
                                    proInfo.SetValue(this, Convert.ToDateTime(objValue), null);
                                    break;
                                case "byte[]":
                                    break;
                                default:
                                    proInfo.SetValue(this, objValue, null);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    
}
